package com.heima.wemedia.feign;

import com.heima.apis.wemedia.IWemediaClient;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.ChannelDto;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.dtos.SensitiveDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.service.WmChannelService;
import com.heima.wemedia.service.WmNewsService;
import com.heima.wemedia.service.WmSensitiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class WemediaClient implements IWemediaClient {

    @Autowired
    private WmChannelService wmChannelService;

    @PostMapping("/api/v1/feign/wemedia/channel/save")
    public ResponseResult insertChannle(@RequestBody WmChannel wmChannel){
        return wmChannelService.insert(wmChannel);
    }

    @PostMapping("/api/v1/feign/wemedia/channel/list")
    public PageResponseResult findChannelList(@RequestBody ChannelDto dto){
        return wmChannelService.findByNameAndPage(dto);
    }

    @PostMapping("/api/v1/feign/wemedia/channel/update")
    public ResponseResult updateChannel(@RequestBody WmChannel wmChannel){
        return wmChannelService.update(wmChannel);
    }

    @GetMapping("/api/v1/feign/wemedia/channel/del/{id}")
    public ResponseResult deleteChannel(@PathVariable("id") Integer id){
        return wmChannelService.delete(id);
    }

    @Override
    @PostMapping("/api/v1/feign/wemedia/channel/findAll")
    public ResponseResult findAllChannel() {
        return wmChannelService.channels();
    }

    @Autowired
    private WmSensitiveService wmSensitiveService;

    @PostMapping("/api/v1/feign/wemedia/sensitive/list")
    public PageResponseResult findSensitiveList(@RequestBody SensitiveDto dto){
        return wmSensitiveService.list(dto);
    }

    @PostMapping("/api/v1/feign/wemedia/sensitive/save")
    public ResponseResult insertSensitive(@RequestBody WmSensitive wmSensitive){
        return wmSensitiveService.insert(wmSensitive);
    }

    @PostMapping("/api/v1/feign/wemedia/sensitive/update")
    public ResponseResult updateSensitive(@RequestBody WmSensitive wmSensitive){
        return wmSensitiveService.update(wmSensitive);
    }

    @GetMapping("/api/v1/feign/wemedia/sensitive/del/{id}")
    public ResponseResult deleteSensitive(@PathVariable("id") Integer id){
        return wmSensitiveService.delete(id);
    }

    @Autowired
    private WmNewsService wmNewsService;

    @PostMapping("/api/v1/feign/news/find_list_vo")
    public PageResponseResult findListNewsVo(@RequestBody NewsAuthDto dto){
        return wmNewsService.findListVo(dto);
    }

    @PostMapping("/api/v1/feign/news/find_news_vo/{id}")
    public ResponseResult findWmNewsVo(@PathVariable("id") Integer id){
        return wmNewsService.findWmNewsVo(id);
    }

    @PostMapping("/api/v1/feign/news/update_wmNews_status/{status}")
    public ResponseResult updateWmNewsStatus(@PathVariable("status") Short status ,@RequestBody NewsAuthDto dto){
        return wmNewsService.updateStatus(status,dto);
    }

    @PostMapping("/api/v1/feign/wemedia/sensitive/import")
    public void importSensitive(@RequestBody List<WmSensitive> wmSensitiveList){
        wmSensitiveService.importAll(wmSensitiveList);
    }

}
